package com.example.zhangpeng.scrollrecyclerview.adapter;

import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zhangpeng.scrollrecyclerview.R;
import com.example.zhangpeng.scrollrecyclerview.view.MyScrollView;

/**
 * Created by zhangpeng on 2017/4/28.
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

    private MyViewHolder myViewHolder;

    public MyViewHolder getMyViewHolder() {
        return myViewHolder;
    }

    public void setMyViewHolder(MyViewHolder myViewHolder) {
        this.myViewHolder = myViewHolder;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        setMyViewHolder(holder);
        holder.scrollView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "点击 ScrollView", Toast.LENGTH_SHORT).show();
            }
        });

//        holder.scrollView.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                Toast.makeText(v.getContext(), "点击 ScrollView onTouch", Toast.LENGTH_SHORT).show();
//                return false;
//            }
//        });

//        holder.scrollView.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                switch (event.getAction()){
//                    case MotionEvent.ACTION_MOVE :
////                        v.getParent().requestDisallowInterceptTouchEvent(true);
//                        break;
//                }

//                return false;
//            }
//        });

        holder.itemView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(v.getContext(), "点击 itemView onTouch ", Toast.LENGTH_SHORT).show();
                return false;
            }
        });
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "点击 itemView", Toast.LENGTH_SHORT).show();
            }
        });
//        holder.tvScrollChild.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Toast.makeText(v.getContext(),"点击 ScrollView 的 ChildView",Toast.LENGTH_SHORT).show();
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return 6;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public MyScrollView scrollView;
        public TextView tvScrollChild;

        public MyViewHolder(View itemView) {
            super(itemView);
            scrollView = (MyScrollView) itemView.findViewById(R.id.scroll_view);
            tvScrollChild = (TextView) itemView.findViewById(R.id.tv_scroll_child);
        }
    }
}
